from flask import Flask, request, jsonify
 
app = Flask(__name__)
 
@app.route('/split_user_info', methods=['POST'])
def process_request():
   data = request.get_json()
   file_url = data.get('file_url')
   file_word = data.get('file_word')
   
   if not file_url or not file_word:
       return jsonify({"error": "Missing file_url or file_word"}), 400
   
   # Splitting file_word by '|' to separate names and action
   parts = file_word.split('|')
   if len(parts) != 2:
       return jsonify({"error": "Invalid format for file_word"}), 400
   
   file_face_names, file_action = parts
   file_face_names = "{" + file_face_names.replace(',', '，') + "}"
   
   response = {
       "file_url": file_url,
       "file_face_name": file_face_names,
       "file_action": file_action
   }
   
   return jsonify(response)

 
@app.route('/filter_results', methods=['POST'])
def filter_results():
   data = request.get_json()
   
   if not data or 'face_name' not in data or 'result' not in data:
       return jsonify({"error": "Invalid aaaaawwwwwwwaaaaaaaaaaaarequest data"}), 400
   
   face_name = data['face_name']
   result = data['result']
   
   # 过滤掉 score 小于 0.95 的结果
   filtered_result = [item for item in result if item['score'] >= 0.95]
   
   response = {
       "face_name": face_name,
       "result": filtered_result
   }
   
   return jsonify(response)

 
if __name__ == '__main__':
   app.run(host='0.0.0.0', port=5001, debug=True)
